package com.weilus.controller;

import com.weilus.entity.TT;
import com.weilus.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Description;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;
import reactor.core.publisher.Mono;


@RestController
@RequestMapping("/tt")
public class TTController {

    @Autowired
    TestService testService;


    //curl http://10.244.1.150:8080/tt
    @GetMapping("")
    @Description("分页查询")
    public Mono<Page<TT>> findAll(
            @RequestParam(required = false,defaultValue = "1")Integer page,
            @RequestParam(required = false,defaultValue = "10") Integer size){
        return testService.page(page,size);
    }

    //curl http://10.244.1.150:8080/tt/1
    @GetMapping("{id}")
    @Description("查询ById")
    public Mono<TT> findById(@PathVariable("id") Long id){
        return testService.findById(id);
    }

    //curl -H "Content-Type: application/json" -X POST  --data '{"name":"德华","age":100,"foo":false}' http://10.244.1.150:8080/tt
    @PostMapping("")
    @Description("新增")
    public Mono<TT> add(@RequestBody TT t){
        return testService.add(t);
    }

    //curl -H "Content-Type: application/json" -X PUT  --data '{"id":1,"name":"刘德华","foo":true}' http://10.244.1.150:8080/tt
    @PutMapping("")
    @Description("修改")
    public Mono<TT> edit(@RequestBody TT t){
        return testService.edit(t);
    }

}
